package mysql

import (
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Mobile    string `gorm:"type:varchar(50);not null;comment:'手机号'"`
	Password  string `gorm:"type:char(32);not null;comment:'密码'"`
	HeadImage string `gorm:"type:varchar(500);not null;comment:'头像'"`
	NickName  string `gorm:"type:varchar(50);not null;comment:'昵称'"`
}

func (u *User) FindUserByMobil(db *gorm.DB, mobile string) error {
	return db.Where("mobile=?", mobile).First(u).Error
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Create(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Where("id=?", id).First(u).Error
}

func (u *User) UpdatePassword(db *gorm.DB, userId int64) error {
	return db.Where("id = ?", userId).Updates(u).Error
}
